home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1996 June / MACPOWER-1996-06.ISO.7z / MACPOWER-1996-06.ISO / MacPowerオリジナル / SILICON MAGIC / リスト / リスト2 next >
Text File  |  1996-04-12  |  5KB  |  137 lines

  1. リスト2 Text2Tableの核心部分
  2.  
  3. CLEAR LOCAL
  4. DIM aRect.8
  5. DIM rowspanMk(_maxRow,_maxCol),rowspan(_maxRow,_maxCol)
  6. DIM colspanMk(_maxRow,_maxCol),colspan(_maxRow,_maxCol)
  7. LOCAL FN DoText2Table(fname$,vRefNum)
  8.   OPEN "I",1,fname$,,vRefNum                      'Open text file for input
  9.   'Step 1 -- Find span marks ( = and " ) and build 2d span mark array
  10.   row=0
  11.   WHILE NOT (EOF(1) OR row>_maxRow)
  12.     INC(row):frstChr=_true
  13.     LINE INPUT #1, txt$                           'Read one line at a time
  14.     col=1
  15.     FOR c=1 TO LEN(txt$)
  16.       c$=MID$(txt$,c,1)
  17.       LONG IF c$=CHR$(34) AND frstChr             'ASCII 34 is double quote
  18.         rowspanMk(row,col)=_true                  'If = or " is only char
  19.       XELSE                                       'in a cell, it is a span
  20.         LONG IF c$="=" AND frstChr                'mark. Multiple chars are
  21.           colspanMk(row,col)=_true                'never treat as a span mark
  22.         XELSE
  23.           LONG IF c$=CHR$(9)
  24.             INC(col)
  25.             frstChr=_true
  26.           XELSE
  27.             rowspanMk(row,col)=_false  
  28.             colspanMk(row,col)=_false
  29.             frstChr=_false
  30.           END IF
  31.         END IF
  32.       END IF
  33.     NEXT
  34.   WEND
  35.   RECORD #1,0                                     'Reset file pointer for Step 3
  36.   lastRow=row:lastCol=col                         'Get last numbers for Step 2
  37.   'Step 2 -- Build cell span arrays
  38.   FOR row=1 TO lastRow
  39.     FOR col=1 TO lastCol
  40.       co=col+1:ro=row+1
  41.       colspan(row,col)=1:rowspan(row,col)=1       'default span = 1
  42.       WHILE colspanMk(row,co)
  43.         INC(colspan(row,col))
  44.         INC(co)
  45.       WEND
  46.       WHILE rowspanMk(ro,col)
  47.         INC(rowspan(row,col))
  48.         INC(ro)
  49.       WEND
  50.     NEXT
  51.   NEXT
  52.   'Step 3 -- Build HTML, open window, and put source into TE fld
  53.   k = FN GetNextWindow
  54.   LONG IF k
  55.     gWindows(k)=0                                 'mark id to be in use
  56.     CALL SETRECT(aRect,10,40,400,460)             'window rect
  57.     winTitle$ = fname$+".html"                    'window title
  58.     WINDOW #-k,winTitle$,@aRect,_docZoom          'make a new window
  59.     TEXT gFont, gSize                             'setup text font & size
  60.     EDIT FIELD #-k,"",(1,1)-(WINDOW(_width)-1,WINDOW(_height)-1),_noFramed
  61.     'styled TE (negative ID edit fld) required for scrollbar/cripboard support
  62.     SCROLL BUTTON #-k,1,1,1,1,,_scrollVert        'vertical scrollbar
  63.     WINDOW #k                                     'show window
  64.     
  65.     tmp$="<TABLE BORDER="+STR$(gBorder)+" CELLPADDING="+STR$(gPadding)+">"+CHR$(13)
  66.     IF gIndent THEN tmp$=tmp$+SPACE$(2)
  67.     FN TEappend(k,tmp$)                           'Put table tag into TE fld
  68.     LONG IF gCaption$<>""
  69.       tmp$="<CAPTION>"+gCaption$+"</CAPTION>"+CHR$(13)
  70.       FN TEappend(k,tmp$)                         'Put caption tag if exists
  71.     END IF
  72.     row=0
  73.     WHILE NOT (EOF(1) OR row>_maxRow)
  74.       INC(row)
  75.       LINE INPUT #1, txt$                         'Read the first line
  76.       'If the first row of the text seems caption...
  77.       LONG IF row=1 AND gCaption$="" AND INSTR(1,txt$,CHR$(9))=0
  78.         tmp$="<CAPTION>"+txt$+"</CAPTION>"+CHR$(13)
  79.         IF gIndent THEN tmp$=tmp$+SPACE$(2)
  80.         FN TEappend(k,tmp$)                       'Put caption tag into TE fld
  81.         LINE INPUT #1, txt$
  82.         INC(row)
  83.       END IF
  84.       tmp$="<TR>"
  85.       IF gIndent THEN tmp$=tmp$+CHR$(13)+SPACE$(4)
  86.       IF gComments THEN tmp$=gLine$+tmp$          'Add devide line into TE fld
  87.       FN TEappend(k,tmp$):tmp$=""
  88.       col=1
  89.       FOR c=1 TO LEN(txt$)
  90.         c$=MID$(txt$,c,1)
  91.         LONG IF c$=CHR$(9)                        'If we reached cell border
  92.           LONG IF NOT(tmp$="=" OR tmp$=""")
  93.             IF gColHeader AND col=1 OR gRowHeader THEN ctag$="TH" ELSE ctag$="TD"
  94.             LONG IF rowspan(row,col)>1
  95.               ctag$=ctag$+" ROWSPAN="+STR$(rowspan(row,col))
  96.             END IF
  97.             LONG IF colspan(row,col)>1
  98.               ctag$=ctag$+" COLSPAN="+STR$(colspan(row,col))
  99.             END IF
  100.             tmp$="<"+ctag$+">"+tmp$+"</"+LEFT$(ctag$,2)+">"
  101.             IF gIndent THEN tmp$=tmp$+CHR$(13)+SPACE$(2)
  102.             IF gIndent AND c<>LEN(txt$)-2*colspan(row,col)+3 THEN tmp$=tmp$+SPACE$(2)
  103.             FN TEappend(k,tmp$)                   'Put a cell into TE fld
  104.           END IF
  105.           INC(col)
  106.           tmp$=""
  107.         XELSE                                     'If not cell border,
  108.           c$=FN NamedEntity$(c$)                  'convert "&<> to named entitiy
  109.           tmp$=tmp$+c$                            'and accumulate chars
  110.         END IF
  111.       NEXT
  112.       'The last cell can't be found by tab, so here we handle the rest of line.
  113.       LONG IF NOT(tmp$="=" OR tmp$=""")
  114.         IF gRowHeader THEN ctag$="TH" ELSE ctag$="TD"
  115.         LONG IF rowspan(row,col)>1
  116.           ctag$=ctag$+" ROWSPAN="+STR$(rowspan(row,col))
  117.         END IF
  118.         tmp$="<"+ctag$+">"+tmp$+"</"+LEFT$(ctag$,2)+">"
  119.         IF gIndent THEN tmp$=tmp$+CHR$(13)+SPACE$(2)
  120.         FN TEappend(k,tmp$)
  121.       END IF
  122.       tmp$="</TR>"+CHR$(13)
  123.       IF gIndent AND row<>lastRow THEN tmp$=tmp$+SPACE$(2)
  124.       FN TEappend(k,tmp$)
  125.       gRowHeader=_false
  126.     WEND
  127.     CLOSE #1                                      'Done with text file
  128.     tmp$="</TABLE>
  129.     FN TEappend(k,tmp$)                           'Put table closing tag
  130.   XELSE
  131.     msg$="Sorry, no more windows can be opened."
  132.     FN DoStopAlert(msg$) 
  133.   END IF
  134. END FN
  135.  
  136.  
  137.